home *** CD-ROM | disk | FTP | other *** search
- /*
- ** DRVALID.C - validate disk drives
- **
- ** Original Copyright 1988-1991 by Bob Stout as part of
- ** the MicroFirm Function Library (MFL)
- **
- ** This subset version is functionally identical to the
- ** version originally published by the author in Tech Specialist
- ** magazine and is hereby donated to the public domain.
- */
-
- #include <dos.h>
- #include <stdlib.h>
-
- typedef enum {ERROR = -1, SUCCESS, FALSE = 0, TRUE} LOGICAL;
-
- /*
- ** getdrv()
- **
- ** Just as getcwd() returns the default directory, getdrv() returns
- ** the current drive.
- **
- ** Arguments: None.
- **
- ** Returns: Current drive (0 = A:, 1 = B:, etc.)
- **
- ** Side effects: none
- */
-
- int getdrv(void)
- {
- union REGS regs;
-
- regs.h.ah = 0x19;
- intdos(®s, ®s);
- return (regs.h.al);
- }
-
- /*
- ** chdrv()
- **
- ** Like chdir(), except changes drives rather than directories.
- **
- ** Arguments: 1 - target drive (0 = A:, 1 = B:, etc.)
- **
- ** Returns: SUCCESS or ERROR
- **
- ** Side effects: none
- */
-
- LOGICAL chdrv(int drive)
- {
- union REGS regs;
-
- regs.h.ah = 0x0e;
- regs.h.dl = (char)drive;
- intdos(®s, ®s);
- if (drive != getdrv())
- return ERROR;
- else return SUCCESS;
- }
-
- /*
- ** drvalid()
- **
- ** Verifies whether a logical disk drive is available without
- ** triggering the DOS critical error handler.
- **
- ** Arguments: 1 - target drive (0 = A;, 1 = B:, etc.)
- **
- ** Returns: TRUE - drive is valid
- ** FALSE - drive is invalid
- **
- ** Side effects: none
- */
-
- LOGICAL drvalid(int drive)
- {
- int original, result;
-
- original = getdrv();
- result = (SUCCESS == chdrv(drive));
- chdrv(original);
- return result;
- }
-